#include <stdio.h>
#include <string.h>

//input n: the nth month
//output int *NumofChildRabbits, int *NumofAdultRabbits
void NumofRabbits(int n, int *NumofChildRabbits, int *NumofAdultRabbits)
{
	if (n < 0)
	{
		*NumofChildRabbits = -1;
		*NumofAdultRabbits = -1;
	}
	if (n == 0)
	{
		*NumofChildRabbits = 1;
		*NumofAdultRabbits = 0;
	}
	else if (n == 1)
	{
		*NumofChildRabbits = 0;
		*NumofAdultRabbits = 1;
	}
	else
	{
		// n >1
		int n1, n2; // n1:NumofChildRabbits; n2:NumofAdultRabbits
		NumofRabbits(n - 1, &n1, &n2);
		*NumofChildRabbits = n2;
		*NumofAdultRabbits = n1 + n2;
	}
}
// The main function
int main(void)
{
	int *res;
	char inputStr[100] = "";
	do
	{
		printf("Please input an integer(<=46) or a command string\n");
		scanf("%s", inputStr);
		int n = atoi(inputStr);
		/*C 库函数 int atoi(const char *str) 把参数 str 所指向的字符串转换为一个整数（类型为 int 型）。
		该函数返回转换后的长整数，如果没有执行有效的转换，则返回零。*/
		int n1,n2;
		long long n3;// The total number
		NumofRabbits(n,&n1,&n2);
		n3 = (long long)n1+(long long)n2;
		printf("There are %d child rabbits\n"
		       "There are %d adult rabbits\n"
		       "The total number of rabbits is %lld\n\n", n1,n2,n3);
	}
	while (strcmp(inputStr, "exit") != 0);

	return (0);
}
